import vtk

from CloudEngine.IO.StandardJsonLoader import StandardJsonLoader
from CloudEngine.core.StandardActor import StandardActor


def release_actor_to_scene(service, loader: StandardJsonLoader, ac: StandardActor):
    line_ac = StandardActor(loader.line_poly_data)
    line_ac.name = f"{ac.name}_line"
    line_ac.set_render_type("SURFACE_WITH_EDGE")
    line_ac.gid = ac.id
    service.model_add(line_ac)
    d3_ac = StandardActor(loader.d3_poly_data)
    d3_ac.name = f"{ac.name}_d3"
    d3_ac.set_render_type("SURFACE_WITH_EDGE")
    d3_ac.gid = ac.id
    d3_ac.visible_off()
    service.model_add(d3_ac)


def get_surface(poly_data):
    surface_filter = vtk.vtkDataSetSurfaceFilter()
    surface_filter.SetInputData(poly_data)
    surface_filter.Update()
    surface_poly_data = surface_filter.GetOutput()
    return surface_poly_data
